﻿@using eLoan.Models;
@model BorrowerSavingsModel

@{
    ViewBag.Title = "Borrower Savings";
}

<div class="row wrapper border-bottom white-bg page-heading">
    <div class="col-lg-10">
        <h2>Borrower Savings</h2>
        <ol class="breadcrumb">
            <li>
                Masterfile
            </li>
            <li>
                <a href="@Url.Action("Borrowers", "Masterfile")">Address Book</a>
            </li>
            <li class="active">
                <strong>Borrower Savings</strong>
            </li>
        </ol>
    </div>
    <div class="col-lg-2"></div>
</div>

<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-lg-8">
            @using (Html.BeginForm("SaveBorrowerSavings", "Borrower", FormMethod.Post, new { id = "saveForm" }))
            {
            @Html.AntiForgeryToken()
            @Html.ValidationSummary(true)
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h3>@Model.BorrowerName</h3>
                    <div>@Html.ValidationMessageFor(m => m.Remarks)</div>
                    <div>@Html.ValidationMessageFor(m => m.Amount)</div>
                </div>
                <div class="ibox-title">
                    <div class="divSearch">
                        <table class="table-search">
                            <tr>
                                <td>@Html.LabelFor(m => m.Remarks)</td>
                                <td>@Html.TextBoxFor(m => m.Remarks, new { @class = "text-box single-line"})</td>
                                <td>
                                    @Html.HiddenFor(m => m.BorrowerID)
                                </td>
                            </tr>
                            <tr>
                                <td>@Html.LabelFor(m => m.Amount)</td>
                                <td>@Html.TextBoxFor(m => m.Amount, "{0:#,###,##0.00}", new { @class = "single-line", @onchange = "FormatMe(this);" })</td>
                                <td style="vertical-align:bottom">
                                    <button type="submit" id="btnSave" class="btn btn-primary btnSearch" name="command" value="Save">Add savings</button>
                                </td>
                            </tr>
                        </table>
                    </div>
                </div>
                <div class="ibox-title">
                    <div class="pull-right">
                        <h3>
                            Total Savings:&nbsp;&nbsp;&nbsp;@Html.ValueFor(m => m.TotalSavings, "{0:#,###,##0.00}")
                        </h3>
                    </div>
                </div>
                <div class="ibox-content">
                    <div class="scrollable">
                        <table class="table table-bordered">
                            <thead class="header">
                                <tr>
                                    <th>Remarks</th>
                                    <th style="width: 150px">Amount</th>
                                    <th style="width: 150px">Date Created</th>
                                    <th style="width: 150px">Created By</th>
                                    
                                </tr>
                            </thead>
                            <tbody>
                                @for (var i = 0; i < Model.Savings.Count(); i++)
                                {
                                    <tr>
                                        <td>@Html.DisplayFor(m => Model.Savings[i].Remarks)</td>
                                        <td>@Html.ValueFor(m => Model.Savings[i].Amount, "{0:#,###,##0.00}")</td>
                                        <td>@Html.ValueFor(m => Model.Savings[i].DateCreated, "{0:MMM/dd/yyyy}")</td>
                                        <td>@Html.DisplayFor(m => Model.Savings[i].CreatedBy)</td>
                                        @*<td>@Html.ActionLink("Delete", "DeleteBorrowerSavings", "Borrower", null, null, null, new { id = Model.Savings[i].ID }, null)</td>*@
                                    </tr>
                                }

                            </tbody>
                        </table>
                    </div>
                </div>
                
            </div>
            }
        </div>
    </div>
</div>

@section Styles {
    @Styles.Render("~/Content/plugins/dataTables/dataTablesStyles")

<style>
    .divSearch {
        background-color: #F5F5F6;
        border: 1px solid #EBEBEB;
        margin-top: 5px;
        padding-top: 10px;
        padding-bottom: 10px;
    }

    .table-search {
        /*width: 30%;*/
        border: none;
    }

        .table-search tr {
            margin-top: 0px;
            margin-bottom: 0px;
            padding-top:0px;
            padding-bottom:0px;
            vertical-align: bottom;
        }

        .table-search td {
            margin-left: 10px;
            margin-right: 10px;
            padding-left: 10px;
            padding-right: 10px;
            padding-top: 5px;
            padding-bottom: 5px;
            vertical-align: bottom;
        }

    .table-search td .btnSearch {
        margin-bottom: 0px;
    }

    .table-search td span {
        margin-left: 5px;
    }

    .scrollable {
        height: 350px;
        overflow-y: scroll;
        border: solid 1px #EBEBEB;
    }
</style>

}

@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
    <script type="text/javascript">

        $(document).ready(function () {

            $(window).keydown(function (event) {
                if (event.keyCode == 13) {
                    event.preventDefault();
                    return false;
                }
            });

        });

        function FormatMe(me) {
            var val = $(me).val().replace(',', '').replace(',', '').replace(',', '');

            if (isNaN(parseFloat(val)))
                val = 0.00;

            var decimalFormat = parseFloat(val).toFixed(2);
            var commaFormat = FormatNumber(decimalFormat);

            $(me).val(commaFormat);
        }

        function FormatNumber(nStr) {
            nStr += '';
            var x = nStr.split('.');
            var x1 = x[0];
            var x2 = x.length > 1 ? '.' + x[1] : '';
            var rgx = /(\d+)(\d{3})/;
            while (rgx.test(x1)) {
                x1 = x1.replace(rgx, '$1' + ',' + '$2');
            }
            return x1 + x2;
        }

    </script>

}
